<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="<%=basePath%>backstage/css/H-ui.min.css" rel="stylesheet"
	type="text/css" />
<link href="<%=basePath%>backstage/css/H-ui.admin.css" rel="stylesheet"
	type="text/css" />
<link href="<%=basePath%>backstage/lib/icheck/icheck.css"
	rel="stylesheet" type="text/css" />
<link href="<%=basePath%>backstage/lib/Hui-iconfont/1.0.6/iconfont.css"
	rel="stylesheet" type="text/css" />
<link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.css"
	rel="stylesheet" type="text/css" />
<link href="lib/region/css/city-picker.css" rel="stylesheet"
	type="text/css" />
<link href="lib/region/css/main.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<link href="<%=basePath%>backstage/css/common.css" rel="stylesheet"
	type="text/css" />
<link href="<%=basePath%>backstage/css/style.css" rel="stylesheet"
	type="text/css" />
<title>添加新发现活动</title>
</head>
<body>
	<div class="pd-20">
		<form action="<%=path%>/backstage/addarticle" method="POST"
			class="form form-horizontal" id="form-u_article-add"
			onsubmit="before_submit()">

			<div class="row cl">
				<label class="form-label col-2"><span class="c-red">*</span>标题：</label>
				<div class="formControls col-6">
					<input type="text" class="input-text" placeholder="" id=""
						name="title" datatype="*" nullmsg="不能为空">
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-2">分类：</label>
				<div id="cat_select_div" class="cat_select_div form-label col-8">
					<div class="cat_select_div_1" style="margin-bottom: 35px;">
						<div class="formControls col-3">
							<select name="first_cate_id" class="select"
								onchange="first_cate_change(this)">
								<option <c:if test="${u_cate.parent_id==-1}">selected</c:if>
									value="0">选择分类</option>
								<c:forEach items="${first_cates}" var="cate">
									<option value="${cate.id}"
										<c:if test="${cate.id==u_cate.parent_id}">selected</c:if>>${cate.cate_full_name}</option>
								</c:forEach>
							</select>
						</div>
						<%-- 	<label class="form-label col-1">二级：</label>
						<div class="formControls col-3">
							<select name="cate_id" class="select second_cates">
								<option <c:if test="${u_cate.parent_id==-1}">selected</c:if>
									value="0">选择二级分类</option>
								<c:forEach items="${second_cates}" var="cate">
									<option value="${cate.id}"
										<c:if test="${cate.id==u_cate.parent_id}">selected</c:if>>${cate.cate_full_name}</option>
								</c:forEach>
							</select>
						</div> --%>
						<%-- <label class="form-label col-1">三级：</label>
						<div class="formControls col-4">
							<select name="cate_id" class="select third_cates"
								onchange="third_cate_change(this)">
								<option <c:if test="${u_cate.parent_id==-1}">selected</c:if>
									value="0">选择三级分类</option>
								<c:forEach items="${third_cates}" var="cate">
									<option value="${cate.id}"
										<c:if test="${cate.id==u_cate.parent_id}">selected</c:if>>${cate.cate_full_name}</option>
								</c:forEach>
							</select>
						</div> --%>
					</div>
				</div>
				<button onClick="cat_select_add();" class="btn btn-primary radius"
					type="button">添加</button>
			</div>

			<div class="row cl">
				<label class="form-label col-2">适应年龄：</label>
				<div class="formControls col-8">
					年龄上限: <input type="text" required class="input-text"
						style="width: 100px;" placeholder="" id="" value="-36500"
						name="apl_up" datatype="*" nullmsg="不能为空">（天）
					&nbsp;&nbsp;年龄下限: <input type="text" required class="input-text"
						style="width: 100px;" placeholder="" id="" value="36500"
						name="apl_down" datatype="*" nullmsg="不能为空">（天）
				</div>
			</div>

			<div class="row cl">
				<label class="form-label col-2">标签：</label>
				<div id="insert3" class="formControls col-8"></div>
			</div>


			<!-- 获取图片地址-->

			<input type="hidden" id="header_img" name="header_img" value="" />
			<div class="row cl">
				<label class="form-label col-2">缩略图：</label>
				<div class="formControls col-10">
					<div class="uploader-thum-container">
						<div id="fileList" class="uploader-list"></div>
						<div id="filePicker">选择图片</div>
						<button id="btn-star" type="button"
							class="btn btn-default btn-uploadstar radius ml-10">开始上传</button>
					</div>

				</div>
			</div>

			<!-- 获取图片地址-->
			<input type="hidden" id="img1" name="img1" value="" />

			<div class="row cl">
				<label class="form-label col-2">图片：</label>
				<div class="formControls col-10">
					<div class="uploader-thum-container">
						<div id="fileList2" class="uploader-list"></div>
						<div id="filePicker2">选择图片</div>
						<button id="btn-star2" type="button"
							class="btn btn-default btn-uploadstar radius ml-10">开始上传</button>
					</div>

				</div>
			</div>


			<div class="row cl">
				<label class="form-label col-2">描述：</label>
				<div class="formControls col-8">
					<input type="text" required class="input-text" placeholder="" id=""
						name="description" datatype="*" nullmsg="不能为空">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-2">序值：</label>
				<div class="formControls col-8">
					<input type="text" required class="input-text" placeholder="" id=""
						value="1000" name="sort" datatype="*" nullmsg="不能为空">
				</div>
			</div>

			<div class="row cl">
				<!--提交前获取编辑器内容-->
				<input type="hidden" id="content" name="content" value=""
					datatype="*" nullmsg="不能为空"> <label
					class="form-label col-2">内容：</label>
				<div class="formControls col-8">
					<script id="editor" type="text/plain"></script>
				</div>
			</div>
			<div class="row cl">
				<div class="col-10 col-offset-2">
					<button onClick="u_article_save_submit();"
						class="btn btn-primary radius" type="submit">保存并提交</button>
					<button onClick="layer_close();" class="btn btn-default radius"
						type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
				</div>
			</div>
		</form>
	</div>
	</div>
	<script type="text/javascript"
		src="<%=basePath%>backstage/lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript"
		src="<%=basePath%>backstage/lib/layer/2.1/layer.js"></script>
	<script type="text/javascript"
		src="<%=basePath%>backstage/lib/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript"
		src="<%=basePath%>backstage/lib/icheck/jquery.icheck.min.js"></script>
	<script type="text/javascript"
		src="<%=basePath%>backstage/lib/Validform/5.3.2/Validform.min.js"></script>
	<script type="text/javascript"
		src="<%=basePath%>plugins/plupload/plupload.full.min.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="<%=basePath%>backstage/lib/ueditor/1.4.3/ueditor.config.js"></script>
	<script type="text/javascript" charset="utf-8"
		src="<%=basePath%>backstage/lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
	<script type="text/javascript" charset="utf-8"
		src="<%=basePath%>backstage/lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>

	<script type="text/javascript" src="<%=basePath%>backstage/js/H-ui.js"></script>
	<script type="text/javascript"
		src="<%=basePath%>backstage/js/H-ui.admin.js"></script>

	<script type="text/javascript">

$(function(){
	//启动调用
	var labels=${labels};
	u_labels_like(labels);
});

// 便签分类
function u_labels_like(labels){
	//empty
	$("#insert3").html("");
	var llength=labels.length;

	var insertObj3="<div id='label1' class='check-box' style='padding-left:0px;' >";

	for(var j=0;j<llength;j++){
		insertObj3=insertObj3+"<div style='line-height:28px;'><label style='font-weight:bold'>"+labels[j].label_name +" : </label>&nbsp;&nbsp;";
		for(var k=0;k<labels[j].child.length;k++){
			insertObj3=insertObj3+"&nbsp;&nbsp;<input type='checkbox' name='label' value="+labels[j].child[k].label_name+" >";
			insertObj3=insertObj3+"&nbsp;&nbsp;<label >"+labels[j].child[k].label_name +"</label>   ";
		}
		insertObj3=insertObj3+"</div>";
	}	
	insertObj3=insertObj3+"</div>";

	$("#insert3").append(insertObj3);

}

function u_article_save_submit(){
	$("#form-u_article-add").Validform({
		tiptype:2,
		ajaxPost:true,
		callback:function(form){
			var index = parent.layer.getFrameIndex(window.name);
			if (index){//关闭弹出层
				parent.$('.btn-refresh').click(); 
				parent.layer.close(index);
			}else{//单独的页面
				location.href = "<%=path%>/backstage/webarticlelist"; 
			}
		}
	});
}

function cat_select_add(){
	var cat_selects = $(".cat_select_div_1").html();
	$(".cat_select_div").append("<div class='cat_select_div_row' >"+cat_selects+"</div>");
}

function cat_selected_remove(id){
	var cat_row = $("#row_cate_"+id);
	cat_row.remove();
}

//初始化Ueditor
$(function(){
	var ue = UE.getEditor('editor');
	
	ue.ready(function(){
		var art_content = $("#content").val();
		ue.setContent(art_content);    
	})
});

function before_submit(){
	//获取内容
	var ue = UE.getEditor('editor');
	var editor_content = ue.getContent();
	$("#content").val(editor_content);
	//
	return true;
}


// 一级分类选择
function first_cate_change(the_select){
	var select_id = the_select.value;
	if (select_id){
		$.ajax({
			type:"GET",
			url:"<%=path%>/backstage/cate_list_by_parent_id",
			dataType: "json",
			data : {id:select_id},
			success : function(msg){
				var cates = msg.datas;
			
				var options = "<option value='-1'>--选择二级分类--</option>";
				for (var i = 0; i < cates.length; i++){
					var aOption = "<option value='"+ cates[i].id+"' >"+ cates[i].cate_name+"</option>"
					options += aOption; 
				}
				var cur_div = $("#cat_select_div").find(".second_cates").last();
				cur_div.html(options);
			}
		});
	}
	///if
	if (select_id){
		$.ajax({
			type:"GET",
			url:"<%=path%>/backstage/cate_lables_by_parent_id",
			dataType: "json",
			data : {id:select_id},
			success : function(msg){
				var cate = msg.datas;
				var cate_labels = cate.u_labels;
				//u_labels_like(cate_labels);
			}
		});
	}
	///if labels
	
}


// 二級分类选择响应
function second_cate_change(the_select){
	var select_id = the_select.value;
	if (select_id){
		$.ajax({
			type:"GET",
			url:"<%=path%>/backstage/cate_list_by_parent_id",
			dataType: "json",
			data : {id:select_id},
			success : function(msg){
				var cates = msg.datas;
				var options = "<option value='-1'>--选择三级分类--</option>";
				for (var i = 0; i < cates.length; i++){
					var aOption = "<option value='"+ cates[i].id+"' >"+ cates[i].cate_name+"</option>"
					options += aOption; 
				}
				var cur_div = $("#cat_select_div").find(".third_cates").last();
				cur_div.html(options);
			}
		});
	}
	///if
	///if
	if (select_id){
		$.ajax({
			type:"GET",
			url:"<%=path%>/backstage/cate_lables_by_parent_id",
			dataType: "json",
			data : {id:select_id},
			success : function(msg){
				var cate = msg.datas;
				//alert(cate);
				var cate_labels = cate.u_labels;
				//u_labels_like(cate_labels);
			}
		});
	}
	///if labels
}


// 三級分类选择响应
function third_cate_change(the_select){
	var select_id = the_select.value;
	///if
	if (select_id){
		$.ajax({
			type:"GET",
			url:"<%=path%>/backstage/cate_lables_by_parent_id",
					dataType : "json",
					data : {
						id : select_id
					},
					success : function(msg) {
						var cate = msg.datas;
						//alert(cate);
						var cate_labels = cate.u_labels;
						//u_labels_like(cate_labels);
					}
				});
			}
			///if labels
		}
	</script>
</body>
</html>

